﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

/// <summary>
/// Params 的摘要说明
/// </summary>
public class Params
{

    public const string SPACE = "&nbsp;";
    public const string SystemError = "SystemError";
    public static string TempString;
    public static bool LockSite;
    public static bool SmtpEnabled;
    public static string SmtpHost;
    public static int SmtpPort;
    public static string SmtpUser;
    public static string SmtpPassword;
    public static int MaxFileSize;
    public const int HourMilliSeconds = 3600 * 1000;
    public const int DayMilliSeconds = 3600 * 1000 * 24;
    public static int WaitMilliSeconds;
    public static string ServerName;
    public static string DataBase;
    public static string UID;
    public static string Pwd;
    public static string Conn;
    public static string RootHttp;
    public static string RootPath;
    public static string BaseFolderHttp;
    public static string BaseFolderPath;
    public static string ImagesFolderHttp;
    public static string ImagesFolderPath;
    public static string FilesFolderHttp;
    public static string FilesFolderPath;
    public static string AdminFolderHttp;
    public static string AdminFolderPath;
    public static string TeamFolderHttp;
    public static string TeamFolderPath;
    public static string StudentFolderHttp;
    public static string StudentFolderPath;
    public static string ExpertFolderHttp;
    public static string ExpertFolderPath;
    public static string DoctorFolderHttp;
    public static string DoctorFolderPath;
    public static string TmpFolderPath;
    public static string TmpFolderHttp;
    public static ydAPI.DBOperate.SQLOperate oPro = new ydAPI.DBOperate.SQLOperate();
    public static System.Random MyRandom;
    public const string ProfilePage = "profile.aspx";

    public static System.Type StrType;
    public static System.Type IntType;

    public static int MinPaperNum;
    public static int MaxPaperNum;

    public static int AdministratorGuid;

    public const string Alpha = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890-=,./<>?!@#$%^&*()_+;':\"[]{}|\\";
    public Params()
    {
        //
        // TODO: 在此处添加构造函数逻辑
        //
    }

    public static void SetParams(DataSet ds, string rp)
    {
        DataRow dr = ds.Tables[0].Rows[0];
        ServerName = dr["Server"].ToString().Trim();
        DataBase = dr["DataBase"].ToString().Trim();
        UID = dr["UID"].ToString().Trim();
        Pwd = dr["Pwd"].ToString().Trim();
        RootHttp = dr["RootHttp"].ToString().Trim();
        Conn = oPro.CreateConnString(ServerName, UID, Pwd, DataBase);
        RootPath = rp;

        FilesFolderPath = RootPath + @"files\";
        FilesFolderHttp = RootHttp + "files/";
        ImagesFolderHttp = RootHttp + "images/";
        ImagesFolderPath = RootPath + @"images\";
        BaseFolderHttp = RootHttp + "base/";
        BaseFolderPath = RootPath + @"base\";
        AdminFolderHttp = RootHttp + "admin/";
        AdminFolderPath = RootPath + @"admin\";
        TeamFolderHttp = RootHttp + "team/";
        StudentFolderHttp = RootHttp + "student/";
        StudentFolderPath = RootPath + @"student\";
        ExpertFolderHttp = RootHttp + "expert/";
        ExpertFolderPath = RootPath + @"expert\";
        DoctorFolderHttp = RootHttp + "doctor/";
        DoctorFolderPath = RootPath + @"doctor\";
        TmpFolderPath = RootPath + @"tmp\";
        TmpFolderHttp = RootHttp + "tmp/";
        Params.MyRandom = new Random(Convert.ToInt32(System.DateTime.Now.Millisecond));

        Params.StrType = System.Type.GetType("System.String");
        Params.IntType = System.Type.GetType("System.Int32");

        Params.ReadSettings();
        Fun.Start();
    }

    public static void ReadSettings()
    {
        string sql = "select * from Settings where Guid="+Fun.GetFirstSettingGuid().ToString();
        DataTable dt = Fun.CreateDt(sql);
        DataRow dr = dt.Rows[0];
        Params.SmtpEnabled = Convert.ToBoolean(dr["SmtpEnabled"]);
        Params.SmtpHost = dr["SmtpHost"].ToString();
        Params.SmtpPassword = dr["SmtpPassword"].ToString();
        Params.SmtpPort = Convert.ToInt32(dr["SmtpPort"]);
        Params.SmtpUser = dr["SmtpUser"].ToString();
        Params.LockSite = Convert.ToBoolean(dr["LockSite"]);
        Params.MinPaperNum = Convert.ToInt32(dr["MinPaperNum"]);
        Params.MaxPaperNum = Convert.ToInt32(dr["MaxPaperNum"]);
        Params.MaxFileSize = Convert.ToInt32(dr["MaxFileSize"]);

        sql = "select top 1 Guid from Users where UserType='"+LwUser.AdminType+"'";
        dt = Fun.CreateDt(sql);
        if (dt.Rows.Count > 0)
        {
            Params.AdministratorGuid = Convert.ToInt32(dt.Rows[0][0]);
        }
        else
        {
            Params.AdministratorGuid = 0;
        }
    }
}
